home *** CD-ROM | disk | FTP | other *** search
- unit ntc_client_search;
- {
- Copyright (C) 2004 - 2006 Andrew Sprott
-
- http://astronomy.crysania.co.uk
- astro@trefach.co.uk
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- }
-
- interface
-
- uses
- Windows,
- Messages,
- SysUtils,
- Variants,
- Classes,
- Graphics,
- Controls,
- Forms,
- Dialogs,
- ExtCtrls,
- StdCtrls,
- Buttons,
- inifiles,
-
- ntc_client_object,
- ntc_client_form;
-
- const
- seconds_in=60*60;
- seconds_in_az=360*seconds_in;
- seconds_in_alt=360*seconds_in;
- degrees_in_quarter=90;
- percent_100=65535;
- { correcting }
- default_intercept=99.834586;
- default_co_efficient_1=0.043221;
- default_co_efficient_2=-0.017952;
- default_co_efficient_3=5.71035432E-05;
- default_height=240;
- default_width=320;
- default_height_part=20;
- default_width_part=20;
- default_seconds=1;
- default_timeout=2000;
-
- type
- button_type_set=(
- b_west,
- b_east,
- b_north,
- b_south);
- button_type=set of button_type_set;
-
- Tscope_search = class(TForm)
- search_panel: TPanel;
- dimensions_group: TGroupBox;
- cycler_group: TGroupBox;
- timeout_edit: TEdit;
- timeout_label: TLabel;
- out_panel: TPanel;
- search_timer: TTimer;
- out_label: TLabel;
- in_panel: TPanel;
- in_label: TLabel;
- clock_panel: TPanel;
- clock_label: TLabel;
- counter_panel: TPanel;
- counter_label: TLabel;
- out_button: TSpeedButton;
- in_button: TSpeedButton;
- clock_button: TSpeedButton;
- counter_button: TSpeedButton;
- reset_group: TGroupBox;
- stop_panel: TPanel;
- stop_button: TSpeedButton;
- stop_label: TLabel;
- reset_panel: TPanel;
- reset_label: TLabel;
- reset_button: TSpeedButton;
- { end test code *** }
-
- { form handlling }
- procedure FormCreate(
- Sender: TObject);
-
- procedure form_close_query(
- Sender: TObject;
- var CanClose: Boolean);
-
- procedure disable_panel;
- procedure enable_panel;
-
- { configuration }
- procedure save_settings;
-
- procedure load_settings;
-
- procedure flip_buttons(
- toggle:boolean);
-
- { slewing functions }
- procedure reset;
-
- procedure move_screen(
- t:string);
-
- { events }
- procedure out_buttonClick(
- Sender: TObject);
-
- procedure change_button(
- button:string);
-
- procedure clock_buttonClick(
- Sender: TObject);
-
- procedure counter_buttonClick(
- Sender: TObject);
-
- procedure in_buttonClick(
- Sender: TObject);
-
- procedure reset_buttonClick(
- Sender: TObject);
-
- procedure stop_buttonClick(
- Sender: TObject);
-
- procedure FormShow(
- Sender:TObject);
-
- procedure adjust;
-
- procedure check_activate(
- Sender: TObject);
-
- { timer }
- procedure enable_timer;
- procedure disable_timer;
- procedure poll_scope;
-
- procedure search_timerTimer(
- Sender: TObject);
-
- procedure timeout_editClick(
- Sender: TObject);
-
- private
- { Private declarations }
- timeout_interval:integer;
- dont_reset:boolean;
- public
- { Public declarations }
- { moving }
- frame_level:integer;
- frame_dir:string;
- { configuration }
- dimensions:dimensions_record;
-
- { events }
- procedure check_visible_and_show_hide(
- sender:tobject);
-
- procedure hide_form;
- procedure show_form;
- end;
-
- var
- scope_search: Tscope_search;
-
- implementation
-
- uses
- ntc_client_network,
- ntc_client_info,
- ntc_client_control;
-
- {$R *.dfm}
- {$R icons.res}
-
- { -------------
- form handling
- ------------- }
-
- procedure Tscope_search.FormCreate(
- Sender: TObject);
- begin
- search_timer.enabled:=false;
- flip_buttons(false);
- load_settings;
- dont_reset:=false;
- end;
-
- procedure tscope_search.form_close_query(
- Sender: TObject;
- var CanClose: Boolean);
- begin
- canclose:=false;
- visible:=false;
- with dimensions do
- begin
- form_top:=top;
- form_left:=left;
- end;
- end;
-
- procedure tscope_search.disable_panel;
- begin
- flip_buttons(false);
- out_button.enabled:=false;
- in_button.enabled:=false;
- clock_button.enabled:=false;
- counter_button.enabled:=false;
- end;
-
- procedure tscope_search.enable_panel;
- begin
- flip_buttons(true);
- out_button.enabled:=true;
- in_button.enabled:=true;
- clock_button.enabled:=true;
- counter_button.enabled:=true;
- end;
-
- procedure tscope_search.FormShow(
- Sender:TObject);
- begin
- with dimensions do
- begin
- top:=form_top;
- left:=form_left;
- end;
- end;
-
- procedure tscope_search.adjust;
- begin
- with dimensions do
- begin
- form_top:=trunc(form_top/last_screen_height*current_height);
- form_left:=trunc(form_left/last_screen_width*current_width);
- end;
- if visible then
- show;
- end;
-
- procedure tscope_search.check_visible_and_show_hide(
- sender:tobject);
- begin
- if visible then
- hide_form
- else
- show_form;
- scope.show_hide(sender,visible);
- end;
-
- procedure tscope_search.hide_form;
- begin
- with dimensions do
- begin
- form_top:=top;
- form_left:=left;
- end;
- Visible:=false;
- end;
-
- procedure tscope_search.show_form;
- begin
- Visible:=true;
- end;
-
- procedure tscope_search.check_activate(
- Sender: TObject);
- begin
- scope.form_activate(scope_search,@dimensions);
- end;
-
- { ---------
- utilities
- --------- }
-
- procedure tscope_search.flip_buttons(
- toggle:boolean);
- begin
- dimensions_group.enabled:=toggle;
- cycler_group.enabled:=toggle;
- end;
-
- { -------------
- configuration
- ------------- }
-
- procedure tscope_search.load_settings;
- begin
- ini_file:=tinifile.create(application_path+'client.ini');
- with ini_file do
- begin
- dont_reset:=true;
- timeout_interval:=readinteger('search','timeout_interval',default_timeout);
- timeout_edit.text:=inttostr(timeout_interval);
- { form }
- scope.get_dimensions(scope_search,@dimensions,'search',ini_file);
- left:=dimensions.form_left;
- top:=dimensions.form_top;
- visible:=readbool('search','visible',false);
- dont_reset:=false;
- end;
- ini_file.free;
- end;
-
- procedure tscope_search.save_settings;
- begin
- with ini_file do
- begin
- writeinteger('search','interval_timeout',timeout_interval);
- { form }
- scope.find_vdu(scope_search,@dimensions);
- scope.write_dimensions(@dimensions,left,top,'search',ini_file);
- writebool('search','visible',visible);
- end;
- end;
-
- { -----------------
- slewing functions
- ----------------- }
-
- procedure tscope_search.reset;
- begin
- if scope_control.moving_scope then
- disable_timer;
- if scope_network.send_request_check('reset_search')>=[exit_ok] then
- frame_level:=0;
- enable_panel;
- end;
-
- { ----------------------------
- move out to larger perimeter
- ---------------------------- }
-
- procedure Tscope_search.move_screen(
- t:string);
- begin
- if scope_network.send_request_check('move_screen_'+t)>=[exit_ok] then
- enable_timer;
- end;
-
- procedure Tscope_search.out_buttonClick(
- Sender: TObject);
- var
- b:string;
- begin
- disable_panel;
- with scope_network do
- if not (send_request_check('break_out')=[exit_ok]) then
- scope_control.write_status_log('invalid response from server')
- else
- begin
- if scope_network.get_string('button',b) then
- change_button(b);
- inc(frame_level);
- enable_timer;
- end;
- end;
-
- { -------------------
- move to inner frame
- ------------------- }
-
- procedure Tscope_search.in_buttonClick(
- Sender: TObject);
- begin
- if frame_level>0 then
- with scope_network do
- begin
- disable_panel;
- if not (send_request_check('fall_in')=[exit_ok]) then
- scope_control.write_status_log('invalid response from server')
- else
- begin
- dec(frame_level);
- enable_timer;
- end;
- end;
- end;
-
- { ------------------
- move to next frame
- ------------------ }
-
- procedure tscope_search.change_button(
- button:string);
- begin
- if button='north' then
- begin
- clock_button.glyph.LoadFromResourceName(hInstance,'NORTH_CLOCK');
- counter_button.glyph.LoadFromResourceName(hInstance,'NORTH_ANTI');
- end
- else if button='south' then
- begin
- clock_button.glyph.LoadFromResourceName(hInstance,'SOUTH_CLOCK');
- counter_button.glyph.LoadFromResourceName(hInstance,'SOUTH_ANTI');
- end
- else if button='east' then
- begin
- clock_button.glyph.LoadFromResourceName(hInstance,'EAST_CLOCK');
- counter_button.glyph.LoadFromResourceName(hInstance,'EAST_ANTI');
- end
- else if button='west' then
- begin
- clock_button.glyph.LoadFromResourceName(hInstance,'WEST_CLOCK');
- counter_button.glyph.LoadFromResourceName(hInstance,'WEST_ANTI');
- end;
- end;
-
- procedure Tscope_search.clock_buttonClick(
- Sender: TObject);
- var
- b:string;
- begin
- disable_panel;
- if scope_network.send_request_check('clockwise')>=[exit_ok] then
- begin
- enable_timer;
- if scope_network.get_string('button',b) then
- change_button(b);
- end
- else
- scope_control.write_status_log('invalid direction');
- end;
-
- procedure Tscope_search.counter_buttonClick(Sender: TObject);
- var
- b:string;
- begin
- disable_panel;
- if scope_network.send_request_check('counter')>=[exit_ok] then
- begin
- enable_timer;
- if scope_network.get_string('button',b) then
- change_button(b);
- end
- else
- scope_control.write_status_log('invalid direction');
- end;
-
- { -----------
- reset event
- ----------- }
-
- procedure Tscope_search.reset_buttonClick(
- Sender: TObject);
- begin
- if not dont_reset then
- reset;
- end;
-
- { ----------
- stop event
- ---------- }
-
- procedure Tscope_search.stop_buttonClick(
- Sender: TObject);
- begin
- if not dont_reset then
- reset;
- scope_control.stop_scope;
- end;
-
- { -----
- timer
- ----- }
-
- procedure tscope_search.enable_timer;
- begin
- scope_control.change_panel(false);
- search_timer.Interval:=timeout_interval;
- search_timer.enabled:=true;
- end;
-
- procedure tscope_search.disable_timer;
- begin
- search_timer.enabled:=false;
- scope_info.show_info;
- scope_control.moving_scope:=false;
- scope_control.change_panel(true);
- end;
-
- procedure tscope_search.poll_scope;
- var
- moving:boolean;
- begin
- with scope_network do
- if send_request_check('stopped')>=[exit_ok] then
- begin
- get_boolean('moving',moving);
- if not moving then
- begin
- scope_control.moving_scope:=false;
- disable_timer;
- end;
- end;
- end;
-
- procedure Tscope_search.search_timerTimer(
- Sender: TObject);
- begin
- if not scope_network.network_timer.enabled then
- poll_scope;
- end;
-
- procedure overlap_change(
- var s:string;
- var def:double);
- var
- d:double;
- begin
- while (length(s)>0) and
- ((copy(s,length(s),1)>'9') or
- (copy(s,length(s),1)<'0')) do
- s:=copy(s,1,length(s)-1);
- if length(s)=0 then
- d:=20
- else
- d:=strtofloatdef(s,def);
- if (d>=0) and (d<100) then
- def:=d
- else
- s:=floattostr(def);
- s:=s+'%';
- end;
-
- procedure Tscope_search.timeout_editClick(
- Sender: TObject);
- begin
- timeout_interval:=strtointdef(timeout_edit.text,2000);
- if timeout_interval<2000 then
- begin
- timeout_interval:=2000;
- timeout_edit.text:=inttostr(timeout_interval);
- end;
- end;
-
- end.
-